package edu.towson.cis.cosc442.project3.vendingmachine;


import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class VendingMachineItemTest {

	/** Declaring necessary test objects for {@link VendingMachine} */
	VendingMachineItem item, item2;
	
	
	/**
	 * Initializes the necessary test objects for the test cases to use.
	 *
	 * @throws Exception the exception
	 */
	@Before
	public void setUp() throws Exception
	{
		item = new VendingMachineItem("testItem", 1.99);
		item2 = new VendingMachineItem("", 0);
	}

	/**
	 * Tests to insure the VendineMachineException class is being called when entering a negative price.
	 */
	@Test(expected = VendingMachineException.class)
	public void testVendineMachineException()
	{
		VendingMachineItem testNegativePrice = new VendingMachineItem("negativePriceItem", -1.0);
	}
	
	/**
	 * 
	 *  Test for the getName() method of the {@link VendingMachineItem} class.
	 */
	@Test
	public void testGetName()
	{
		assertEquals("testItem", item.getName());
		assertEquals("", item2.getName());
	}
	
	/**
	 *  Test for the getPrice() method of the {@link VendingMachineItem} class.
	 */
	@Test
	public void testGetPrice()
	{
		assertEquals(1.99, item.getPrice(), 0.001);
		assertEquals(0, item2.getPrice(), 0.001);
	}
	
	/**
	 * Tests the VendingMachineItem constructor of the {@link VendingMachineItem} class.
	 * Runs after the test for getName() and getPrice() methods to insure that they are working properly first
	 * @param name
	 * @param price
	 */
	@Test
	public void testVendingMachineItem()
	{
		assertEquals("testItem", item.getName());
		assertEquals(1.99, item.getPrice(),0.001);
		
		assertEquals("", item2.getName());
		assertEquals(0, item2.getPrice(),0.001);
	}
	
	/**
	 * Cleans up test objects after a test case is executed.
	 */
	@After
	public void tearDown(){
		item = null;
		item2 = null;
	}
}
